<template>
  <div>
     <h2>随机点名</h2>
    <div class="box">
      <span>名字是：</span>
      <div class="qs">{{msg}}</div>
    </div>
    <div class="btns">
      <button class="start" @click="add">开始</button>
      <button class="end" @click="stopup">结束</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'WorkspaceJsonApp',

  data() {
    return {
      msg:'这里显示姓名',
      name:['赵云','马超','张飞','黄忠','关羽','刘备','吴志宇','龚意'],
      timer:null
    };
  },

  methods: {
    add(){
       clearInterval(this.timer)
      this.timer=setInterval(()=> {
        let index = Math.floor(Math.random() * (this.name.length+1))
        this.msg = this.name[index]
      },200)
    },
    stopup(){
    clearInterval(this.timer)
    }
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
}

.box {
  width: 600px;
  margin: 50px auto;
  display: flex;
  font-size: 25px;
  line-height: 40px;
}

.qs {
  width: 450px;
  height: 40px;
  color: red;
}

.btns {
  text-align: center;
}

.btns button {
  width: 120px;
  height: 35px;
  margin: 0 50px;
}
</style>